//
//  DKMessageViewController.m
//  BTApp
//
//  Created by 丁侃 on 16/4/17.
//  Copyright © 2016年 丁侃. All rights reserved.
//

#import "DKMessageViewController.h"
#import "DKCommentViewController.h"
#import "DKLikeViewController.h"
#import "DKNotiViewController.h"

#import "DKTopItemView.h"
#import "DKbackImage.h"



static CGFloat const backGroundImageY = 200;


@interface DKMessageViewController()<UIScrollViewDelegate>

/*
@property (nonatomic, weak) DKTopItemView *topBar;

@property (nonatomic, weak) UIScrollView *mainView;

@property (nonatomic, assign) CGFloat preOffsetX;

//子控制器标题数组
@property (nonatomic, strong) NSMutableArray<NSString *> *items;
*/
@end

@implementation DKMessageViewController

#pragma  mark -------------------------------
#pragma  mark - 懒加载
/*
-(NSMutableArray *)items
{
    if (!_items) {
        _items = [NSMutableArray array];
    }
    return _items;
}

-(UIScrollView *)mainView
{
    if (!_mainView) {
        
        UIScrollView *mainView = [[UIScrollView alloc]initWithFrame: CGRectMake(0, CGRectGetMaxY(self.topBar.frame), self.view.width, (self.view.height - CGRectGetMaxY(self.topBar.frame)))];
        
        mainView.contentSize = CGSizeMake(self.childViewControllers.count * self.view.width, 0);
        
        mainView.pagingEnabled = YES;
        
        [self.view addSubview:mainView];
        
        //监听scrollview的滚动
        mainView.delegate = self;
        
        _mainView = mainView;
    }
    return _mainView;
}

-(DKTopItemView *)topBar
{
    if (!_topBar) {
        DKTopItemView *topBar = [[DKTopItemView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 44)];
        
        topBar.backgroundColor = [UIColor whiteColor];
        
        topBar.items = self.items;
        
        [self.view addSubview:topBar];
        
        _topBar = topBar;
    }
    return _topBar;
}
*/
-(void)viewDidLoad
{
    [super viewDidLoad];

    //添加子控制器
    [self addChildViewControllers];

    [self addBackGroundImage];
}

//设置背景图片
-(void)addBackGroundImage
{
    
    CGFloat imageX = self.view.width * 0.5;
    
    for (NSInteger i = 0; i < self.childViewControllers.count; i ++) {
        
        DKbackImage *backImage = [DKbackImage backImage];
        
        backImage.center = CGPointMake( imageX + i * self.view.width, backGroundImageY);
        
        [self.bottomView addSubview:backImage];
    }
}

#pragma  mark -------------------------------
#pragma  mark -添加子控制器

//添加子控制器
-(void)addChildViewControllers
{
    //喜欢
    DKLikeViewController *likeVc = [[DKLikeViewController alloc]init];
    [self addOneChildVc:likeVc withTitle:@"喜欢"];
    
    //评论
    DKCommentViewController *commentVc = [[DKCommentViewController alloc]init];
    [self addOneChildVc:commentVc withTitle:@"评论"];
    
    //通知
    DKNotiViewController *notiVc = [[DKNotiViewController alloc]init];
    [self addOneChildVc:notiVc withTitle:@"通知"];
}

//添加一个子控制器
-(void)addOneChildVc:(UIViewController *)vc withTitle:(NSString *)title
{
    vc.title = title;
    [self addChildViewController:vc];
}


@end
